%%%-------------------------------------------------------------------
%%% @author Rain
%%% @copyright (C) 2022, <COMPANY>
%%% @doc 排行榜定制数据模块 - 用于定制不同类型排行榜不同数据
%%%
%%% @end
%%% Created : 31. 3月 2022 17:57
%%%-------------------------------------------------------------------
-module(rank_util).
-author("Rain").
-include("player.hrl").
-include("rank.hrl").

%% API
-export([make_rank_data/3,
    get_rank_brief_one/2]).


make_rank_data(?RANK_TYPE_LEVEL, _UserData = #player{uuid = Uuid, level = Level}, BaseRankData) ->
    SubmitTime = os:system_time(),
    RankKey = {-Level, SubmitTime, Uuid},
    BaseRankData#rank_data{key = Uuid, value = Level, rank_key = RankKey};
make_rank_data(?RANK_TYPE_POWER, _UserData = #player{uuid = Uuid, power = Power}, BaseRankData) ->
    SubmitTime = os:system_time(),
    RankKey = {-Power, SubmitTime, Uuid},
    BaseRankData#rank_data{key = Uuid, value = Power, rank_key = RankKey};
make_rank_data(RankType, _, _) ->
    ErrorTip = io_lib:format("ERROR: make_rank_data ~p", [RankType]),
    throw(ErrorTip).


%% @doc 获取单个Brief
%% TODO 目前实例为从数据中直接取，后续为使用通用接口获取
get_rank_brief_one(?RANK_BRIEF_KEY_NAME, #player{name = Name} = _UserData) ->
    Name;
get_rank_brief_one(?RANK_BRIEF_KEY_LEVEL, #player{level = Level} = _UserData) ->
    Level;
get_rank_brief_one(?RANK_BRIEF_KEY_ICON, #player{icon = Icon} = _UserData) ->
    Icon;
get_rank_brief_one(?RANK_BRIEF_KEY_SEX, #player{sex = Sex} = _UserData) ->
    Sex;
get_rank_brief_one(_, _) ->
    undef.